<template>
	<view>
		<view class="top-box">
			<!-- 自定义导航栏 -->
			<view :style="'height:' + statusBarHeight + 'px'"/>
			<view class="navTopBox" :style="'height:' + navBarHeight + 'px'">
				<view class="left-button-box" :style="'height:' + menuButtonInfo.height + 'px;margin-top:'+(menuButtonInfo.top - statusBarHeight)+'px'">
					<image @click="tapToBack('back')" src="../../static/detail/back.png" mode="aspectFill"></image>
					<view class="line"></view>
					<image src="../../static/detail/home.png" mode="aspectFill" @click="tapToBack('index')"></image>
				</view>
				
				<view :style="'line-height:'+ navBarHeight + 'px;'" class="pageTitle">{{title}}</view>
			</view>
		</view>
		
		<view :style="'height:' + (statusBarHeight + navBarHeight) + 'px'">
		</view>
	</view>
</template>

<script>
	var app = getApp();
	
	export default {
		name:"top-nav",
 
		props:{
			title:String
		},
		data() {
			return {
				statusBarHeight : app.globalData.statusBarHeight,
				navBarHeight : app.globalData.navBarHeight,
				menuButtonInfo : app.globalData.menuButtonInfo
			};
		},
		methods: {
			// 返回按钮
			tapToBack(page) {
				switch(page){
					case 'index':
						uni.switchTab({
							url:'/pages/index/index'
						})
					break;
					case 'back':
						uni.navigateBack({
							delta:1,
							fail() {
								uni.switchTab({
									url:'../mine/mine'
								})
							}
						})
					break;
				}
			},
		}
	}
</script>

<style lang="scss">
	.top-box {
		position: fixed;
		top: 0;left: 0;
		background-color: #fff;
		width: 100vw;
		z-index: 10;
	}
	.navTopBox {
		display: flex;
		position: relative;
		
		.pageTitle {
			width: 300rpx;
			position: absolute;left: 50%;
			margin-left: -150rpx;
			text-align: center;
			overflow: hidden !important;
			text-overflow: ellipsis !important;
			display: -webkit-box !important;
			-webkit-line-clamp: 1;//文字上限行
			-webkit-box-orient: vertical;
			font-size: 32rpx;
			font-weight: bold;
			color: #333333;
		}
		.left-button-box {
			width: 150rpx;
			background-color: rgba(255,255,255,.2);
			border-radius: 40rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			margin-left: 30rpx;
			border: 1rpx solid rgba(224, 224, 224, 0.5);
			
			.line {
				height: 30rpx;
				background: #BABABA;
				width: 1rpx;
			}
			
			image {
				width: 30rpx;
				height: 30rpx;
				margin: 0 20rpx;
			}
		}
	}
</style>